﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ExcelToSqlserver
{
    public partial class ColumnSet : Form
    {
        ETOSMain Par;
        public ColumnSet(ETOSMain Parent)
        {
            InitializeComponent();
            this.Par = Parent;
        }

        private void ColumnSet_Load(object sender, EventArgs e)
        {
            try
            {
                left.Items.Clear();
                left.DataSource = Par.CKeyValue.Where(t => string.IsNullOrWhiteSpace(t.Value)).ToList();
                left.DisplayMember = "key";
                right.Items.Clear();
                right.Items.AddRange(TemplateType.ColumnNames.ToArray());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Par.CKeyValue[left.Text.ToString()] = right.SelectedItem.ToString().Split('-')[0].Trim();
            this.Par.SetColumn(left.Text.ToString(), right.SelectedItem.ToString().Split('-')[0].Trim());
            left.DataSource = null;
            left.DataSource = Par.CKeyValue.Where(t => string.IsNullOrWhiteSpace(t.Value)).ToList();
            left.DisplayMember = "key";
        }
    }
}
